<?php use_helper('Javascript') ?>

<?php /* @var $category Category */ ?>
<?php if( !empty($arCategories) ): ?>
	<ul>
	<?php $arParentsId = Category::getParentsId($id); ?>
	
	<?php //$arBranch = Category::getBranchById($id); ?>
    
	<?php foreach( $arCategories as $category ): ?>

    <?php //$find = array_search($category->getId(), $arParentsId); ?>
    <?php //debugvar($arParentsId, 'arParentsId'); ?>
    <?php //debugvar($find, 'find'); ?>

		<?php if($category->getChildrenQnt()): ?>
                <?php echo link_to('<li>' . $category->getName() . '</li>'
                                , '#'
                                , array('onclick' => 'onCategoryClicked('. $category->getId() .')'))?>
        <?php else: ?>
            <?php echo link_to('<li>' . $category->getName() . '</li>'
                            , 'product/list?id=' . $category->getId()); ?>
        <?php endif; ?>
        <div id="category_child_<?php echo $category->getId() ?>"></div>
    <?php endforeach; ?>
    </ul>
<?php else: ?>
    No categories
<?php endif; ?>
<script type="text/javascript">
function onCategoryClicked(id)
{
    jQuery.ajax({
        type: "post"
        , data: ({'id' : id })
        , dataType: "html"
        , url: "/public_html/test.php/category/detail"
        , success: function(data) {
            jQuery('#category_child_'+id).html(data);
          }
    });
}
</script>